/**
 * 防抖代码的实现
 */

function debounce(fn,delay){
    let timer = null;
    return function(...args){
        if(timer){
            clearTimeout(timer);
        } //如果timer有值,则说明上次回调还在等待执行,清除定时器重新等待
        timer = setTimeout(()=>{
            fn.apply(this,args)
        },delay)
    }
}

function add(){
    console.log(111)
}

const tadd = debounce(add,3000)

tadd()
tadd()
tadd()